import React, {useContext} from 'react';
import {View, Image, Alert, Platform, ScrollView, FlatList} from 'react-native';
import dayjs from 'dayjs';
import Toast from 'react-native-root-toast';
import {useNavigation} from '@react-navigation/native';
import {useMount, useUnmount, useSafeState} from 'ahooks';
import {Text, Button, Input, Dialog, ListItem, Avatar} from '@rneui/themed';
import FontAwesome5 from 'react-native-vector-icons/FontAwesome5';
import {useSelector, useDispatch} from 'react-redux';
import GlobalContext from '@/GlobalContext';
import ImagePicker from 'react-native-image-crop-picker';
import fileExtension from 'file-extension';
import {ApiHost, OssHost} from '@/config/common';
import {setKeyGetAccountInfo} from '@/store';
import DocumentPicker from 'react-native-document-picker';

const leftIconSize = 18;
const rightIconSize = 20;

import RNFS from 'react-native-fs';
import RNFetchBlob from 'react-native-blob-util';
import {Dirs, FileSystem} from 'react-native-file-access';
import putFileToOss from '@/fun/putFileToOss';
import globalStyle from '@/style/global.less';
import {round} from 'lodash';

const getSizeTxt = size => {
  if (size < 1024) {
    return `${size}B`;
  } else if (size < 1024 * 1024) {
    return `${round(size / 1024, 2)}KB`;
  } else if (size < 1024 * 1024 * 1024) {
    return `${round(size / 1024 / 1024, 2)}MB`;
  } else {
    return `${round(size / 1024 / 1024 / 1024, 2)}GB`;
  }
};

export default ({item = {}, setOpenDirPath}) => {
  const navigation = useNavigation();
  const dispatch = useDispatch();
  const token = useSelector(state => state.token.value);
  const accountInfo = useSelector(state => state.accountInfo.value);
  let defaultUri = accountInfo?.j_ext_info?.photo_relative_path;
  if (defaultUri) {
    defaultUri = `${OssHost}/${defaultUri}`;
  }
  // useMount(() => {
  //   console.log('挂载', item.path);
  // });
  // useUnmount(() => {
  //   console.log('卸载', item.path);
  // });
  const [checked, setChecked] = useSafeState([false, false]);
  return (
    <ListItem
      onPress={() => {
        // setOpenDirPath(item.path);
      }}
      style={{
        marginTop: 2,
      }}>
      <ListItem.Content>
        <ListItem.Title>{item.filename}</ListItem.Title>
        <Text style={{color: '#999999'}}>{getSizeTxt(item.size)} </Text>
      </ListItem.Content>
    </ListItem>
  );
};
